package com.spring.springbootblog.controller;


import com.spring.springbootblog.common.pojo.request.AddBlogParam;
import com.spring.springbootblog.common.pojo.request.UpBlogParam;
import com.spring.springbootblog.common.pojo.response.BlogDetailResponse;
import com.spring.springbootblog.common.pojo.response.BlogInfoResponse;
import com.spring.springbootblog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;


    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList(){
        log.info("获取博客列表");
        return blogService.getList();
    }
    @RequestMapping("/getBlogDetail")
    public BlogDetailResponse getBlogDetail(@NotNull Integer blogId){
        log.info("获取博客详情:blogId={}",blogId);
        return blogService.getBlogDetail(blogId);
    }
    @RequestMapping("/add")
    public Boolean addBlog(@Validated @RequestBody AddBlogParam param){
        log.info("添加博客");
        return blogService.addBlog(param);
    }

    @RequestMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpBlogParam param){
        log.info("更新博客,blogId={}",param.getId());
        return blogService.updateBlog(param);
    }
    @RequestMapping("/delete")
    public Boolean deleteBlog(@NotNull Integer blogId){
        log.info("删除博客,blogId={}",blogId);
        return blogService.deleteBlog(blogId);
    }
}
